const computeNum = (computeType, num1, num2) => {
  if (!['add', 'subtr', 'mul', 'div'].includes(computeType)) {
    console.error('computeNum函数参数错误，“computeType”计算类型！', computeType)
    return
  } else if (
    !/^-?[0-9]+\.?[0-9]*$/.test(num1) ||
    !/^-?[0-9]+\.?[0-9]*$/.test(num2)
  ) {
    console.error('computeNum函数参数错误，第二参数或第三参数非数字！', num1, num2, computeType)
    return
  }
  var r1, r2, m, res;
  try { r1 = num1.toString().split('.')[1].length } catch (e) { r1 = 0 }
  try { r2 = num2.toString().split('.')[1].length } catch (e) { r2 = 0 }
  m = Math.pow(10, Math.max(r1, r2))
  let _num1 = Number(num1.toString().replace('.', ''))
  let _num2 = Number(num2.toString().replace('.', ''))
  if (r1 > r2) {
    _num2 = _num2 * Math.pow(10, r1 - r2)
  } else if (r1 < r2) {
    _num1 = _num1 * Math.pow(10, r2 - r1)
  }
  switch(computeType) {
    case 'add':
      res = (_num1 + _num2) / m
      break
    case 'subtr':
      res = (_num1 - _num2) / m
      break
    case 'mul':
      res = _num1 * _num2 / Math.pow(m, 2)
      break
    case 'div':
      res = _num1 / _num2
      break
  }
  isNaN(res) && (res = 0)
  return res
}

// console.log(computeNum('div', 100.5, 2))
console.log(computeNum('mul', 100.5, 2))